package Test1;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;

public class CharCount {
	public static void main(String[] args) {
		read();
	}
	
	public static void read() {
		try {
		File readfile = new File("Jimmy Neutron.txt");
		FileInputStream fis = new FileInputStream(readfile);
		DataInputStream dis = new DataInputStream(fis);
		File output = new File("out.txt");
		FileOutputStream outstream = new FileOutputStream(output);
		
		StringBuilder buff = new StringBuilder();
				
				buff.append(dis.readLine());
				String str = buff.toString();
				String[] a = str.split(" "); //string displit berdasarkan spasi
				Character[] ch = new Character[str.length()];
		
				for (int gj = 0; gj < str.length(); gj++) {
					ch[gj] = buff.charAt(gj); //ambil karakter
				}
		
				HashSet cch = new HashSet(Arrays.asList(ch)); //bikin hashset untuk array ch
				HashSet s = new HashSet(Arrays.asList(a));   //bikin hashet untuk array string a
		
				for (Iterator i = s.iterator(); i.hasNext();) {
					Object z = i.next();
					int karSame = 0;
					for (int j = 0; j < a.length; j++) {
						if (z.equals(a[j])) { //cocokan kata
							karSame++;
						}
					}
				}
				
				for (Iterator i = cch.iterator(); i.hasNext();) {
					Object kar = i.next();
					int sameKar = 0;
					for (int j = 0; j <ch.length; j++) {
						if (kar == ch[j]) { //cocokan karakter
							sameKar++;
						}
					}
					// Menulis kedalam file
					String tmp= (kar.toString() + " = " + Integer.toString(sameKar) + "\r\n");
					outstream.write(tmp.getBytes());
				}
		} catch (Exception e1) {
			System.out.println("error : " + e1);
		}
	}
}
